<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAreasTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('areas') && \App\B2BProject\Area::count() > 5000) {
            return;
        }

        Schema::create('areas', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('parent_id')->default(0)->unsigned();
            $table->tinyInteger('level')->default(1)->unsgined();
            $table->string('name');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (Schema::hasTable('areas') && \App\B2BProject\Area::count() < 5000) {
            Schema::drop('areas');
        }
    }
}
